

#include <GridClient.h>
#include "BehaviorGridClient.h"
#include "gridprotocol.pb.h"
#include <stdlib.h>
#include <iostream>

using namespace Network;
using namespace MasterWorkerFramework;

int main()
{

	  try {
		std::string ip;
		PrintLog("Client started");
		PrintLog("Server IP:");
		std::getline(std::cin, ip);
		Sleep(5000);
		//initialize boost ioservice
		boost::asio::io_service service_client;
		//bind client socket to the server socket
		asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(ip), 4050);
		//initialize the BehaviorGridClient implementation
		BehaviorGridClient* behavior = new BehaviorGridClient();
		//initialize the client with as args the service, the enpoint and the behavior handler
		GridClient<gridprotocol::Request,gridprotocol::Response>* client = 
			new GridClient<gridprotocol::Request,gridprotocol::Response>(service_client, endpoint,behavior);
		//deconnection of ioservice execution & client initialization for flexibility purpose (ie timelaps between server inialization & client registration)
		service_client.run();
		return 0;
    }
	  //catch any execption (ie server inactive)
    catch (std::exception& e) {
        cerr << e.what() << endl;

    }

	return 0;
}

